﻿using System;
using System.Collections.Generic;

namespace ExcelConfig.Config
{
    using ExcelConfig.helpers;

    public class SheetLine
    {
        internal IDictionary<string, object> OBJ { get; set; }
        public SheetLine() { 
            this.OBJ = new Dictionary<string, object>();
        }
        internal SheetLine(IDictionary<string, object> oBJ)
        {
            OBJ = oBJ;
        }
        public ICollection<string> Keys {  get { return this.OBJ.Keys; } }
        public string Text(string name)
        {
            if (OBJ.ContainsKey(name))  return helper.parse_to_text(OBJ[name]);
            return string.Empty;
        }
        public decimal Number(string name)
        {
            if (OBJ.ContainsKey(name)) return helper.parse_to_number(OBJ[name]);
            return 0;
        }
        public bool YesOrNo(string name)
        {
            return Text(name) == ExcelConfigSetting.YES;
        }
        public string[] Array(string name)
        {
            var arr = new Queue<string>();
            foreach (var text in LoopArray(name)) arr.Enqueue(text);
            return arr.ToArray();
        }
        public IEnumerable<string> LoopArray(string name)
        {
            var arr = Text(name).Split(ExcelConfigSetting.ArraySplitChar);
            for (var i = 0; i < arr.Length; i++) if (!string.IsNullOrEmpty(arr[i])) yield return arr[i];
        }
    }
}
